package rrrmai.activity;

import android.databinding.DataBindingUtil;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.design.widget.TabLayout;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.view.View;
import android.widget.Toast;

import com.jakewharton.rxbinding2.support.design.widget.RxTabLayout;
import com.jakewharton.rxbinding2.support.design.widget.TabLayoutSelectionEvent;
import com.xgggh.rrrmai.R;
import com.xgggh.rrrmai.databinding.ActivityCommentBinding;

import io.reactivex.functions.Consumer;
import xgggh.activity.BaseActivity;

public class CommentActivity extends BaseActivity {
    ActivityCommentBinding mBinding;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mBinding=DataBindingUtil.setContentView(this,R.layout.activity_comment);
        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        onBind();

        FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
        fab.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
                        .setAction("Action", null).show();
            }
        });
    }



    private void onBind(){
        RxTabLayout.selections(mBinding.contentComment.tabComment)
                .compose(bindToLifecycle())
                .subscribe(new Consumer<TabLayout.Tab>() {
            @Override
            public void accept(TabLayout.Tab tab) throws Exception {
                onTab(tab);
            }
        });
    }

    private void onTab(TabLayout.Tab tab){
         int pos=tab.getPosition();
        Toast.makeText(this, "pos"+pos, Toast.LENGTH_SHORT).show();
        //mBinding.contentComment.tabComment.getTabAt(0);
    }

}
